<!DOCTYPE HTML>
<html>
<head>

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title>RRKEMR_Print003</title>
	<script type="text/javascript" src="../third-party/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../ueditor.oneEditorPrint.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="editor_api_oneEditorPrint.js"></script>
</head>
<body>
    <h1>RRKEMR_Print003</h1>

	<h2><input type="button" id="btn02" value="My Iframe打印"></h2>
    <!--style给定宽度可以影响编辑器的最终宽度-->
    <script type="text/plain" id="myEditor" style="width:1024px;height:500px;">
        <p>这里我可以写一些输入提示</p>
    </script>
    <script type="text/javascript">
        var editor01 = UE.getEditor('myEditor');
		$(function(){
			var btn02 = $('#btn02');
			
			btn02.on('click', function(){
				console.log( editor01 );
				
				var UE_html = editor01.getAllHtml();
				// console.log( UE_html );
				// return false;
				
				var $ifr_00 = $('#ifr_00');
				/*if($ifr_00.length == 0){
					var tplIfr = '<iframe id="ifr_00" style="width:0;height:0;"></iframe>';
					$('body').append( tplIfr );
				}*/
				if($ifr_00[0]){
					$ifr_00.remove();
				}
				
				var tplIfr = '<iframe id="ifr_00" style="width:0;height:0;"></iframe>';
				$('body').append( tplIfr );
				
				setTimeout(function(){
					$ifr_00 = $('#ifr_00');
					if($ifr_00[0]){
						var _ifr = $ifr_00[0];
						var _doc = _ifr.contentWindow.document;
						
						_doc.open();
						_doc.write( UE_html );
						// _doc.write( '<script type="text\/javascript">alert(11);<\/script>' );
						// _doc.write( '<script type="text\/javascript">window.onload=function(){window.print();};<\/script>' );
						_doc.close();
						
						setTimeout(function(){
							/*_ifr.contentWindow.onload = function(){
								// window.print();
								var _body = $(_doc.body);
								var _arr = _body.find('*');
								console.log( _arr.length );
								var _height = 0
									, _i = 0;
								$.each(_arr, function(i,n){
									//console.log(i+" : , "+n.nodeType, n.nodeName);
									if("P" == n.nodeName){
										_i ++;
										_height += $(n).innerHeight();
										console.log( '$(n).innerHeight(): ', $(n).innerHeight() );
									}
								});
								console.log( '_i: ',_i );
								console.log( '_height: ',_height );
								console.log( '_body.height: ',_body.height() );
								
								_ifr.contentWindow.print();
							};*/
							$(_ifr.contentWindow.document).ready(function(){
								var _body = $(_ifr.contentWindow.document.body);
								var _arr = _body.find('*');
								var _height = 0
									, _i = 0;
								$.each(_arr, function(i,n){
									//console.log(i+" : , "+n.nodeType, n.nodeName);
									if("P" == n.nodeName){
										_i ++;
										_height += $(n).innerHeight();
										console.log( '$(n).innerHeight(): ', $(n).innerHeight() );
									}
								});
								console.log( '_i: ',_i );
								console.log( '_height: ',_height );
								console.log( '_body.height: ',_body.height() );
								
								_ifr.contentWindow.print();
							});
						}, 1);
						
						/*setTimeout(function(){
							_ifr.contentWindow.print();
							console.log( $ifr_00[0].contentWindow.document );
						}, 30);*/
						
						/*setTimeout(function(){
							var _win = $( _ifr.contentWindow );
							_win.on('load', function(){
								alert(11);
							});
						}, 5);*/
						
						// console.log( $ifr_00[0].contentWindow );
						// console.log( $ifr_00[0].contentDocument );
						
					}
				},1);
			});
		});
// window.onload=function(){window.print();};
    </script>

</body>


</html>
